* Martin Macias-Medellin & Aldo F. Ponce
* Strategic Resources for Drug Trafficking Organizations and the Geography of Violence: Evidence from Mexico
* Latin American Politics and Society

* Replication

* Variables
/*
*inter_dto_kill: Inter DTO Deaths/Inter DTO Violence
*lagged_inter_kill: Inter DTO Deaths/Inter DTO Violence lagged 1 year
*total_deaths: Total Deaths/Total Violence
*lagged_total_deaths: Total Deaths/Total Violence lagged 1 year
*lagged_log_detain: Detained DTO Members (logged, t-1)
*log_dist_border100: Distance to Closest Border Segment (100 km, logged)
*log_dist_border50: Distance to Closest Border Segment (50 km, logged)
*log_dist_border:  Distance to US border (logged)	
*log_dist_ports_entry: Distance to Closest Entry Port (logged)
*log_dist_ports_highways: Distance to Closest Port Closest to Highways (logged)
*log_dist_pipelines: Distance to Closest Pipeline (logged)
*log_dist_portsnm: Distance to Closest Port (logged)
*log_dist_airports: Distance to Closest Airport (logged)
*log_dist_highways: Distance to Closest Highway (logged)
*fragment: Number of DTOs
*lagged_fragment: Number of DTOs lagged 1 year
*pan_lajous: PAN mayor
*pri_lajous: PRI mayor
*prd_lajous: PRD mayor
*prigob PRI: governor
*pangob PAN: governor
*zetas: Zetas
*beltran_leyva2: Beltran Leyva
*sinaloa2: Sinaloa
*familia: Familia
*golfo: Golfo
*juarez: Juarez
*tijuana: Tijuana
*grado_rezago: Social Development
*log_pob: Population (logged)
*illiteracy: Schooling
*male_occupied: Percent of Occupied Male
*opium_percent: Opium Suitability Area
*cambio_partido_lajous: Party Change
*dto_kill: Killed DTO Members
*log_dto_kill: Killed DTO Members (logged)
*lagged_log_dto_kill: Killed DTO Members (logged) lagged 1 year
*grado_marginacion: Marginalization Degree
*male_occupied: Percent of Occupied Male
*opium_percent:	Opium Suitability Area		
*cambio_partido_lajous: Party Change
*refinery_dummy: Refinery in the municipality
*refinery_pipelines: Refinery x Distance to Closest Pipeline (logged)
*repress_dummy: Killed DTOs
*repress_highways: Killed DTOs x Distance to Closest Highway	
*urban2: whether the locality is urban (2500 inhabitants or more or municipal capital)
*urban3: whether the locality has more than 2500 inhabitants
*id_estado: State id
*cvegeo: Locality id
*/


use "Base Macias and Ponce.dta", clear

* Table 1. Mediation Negative Binomial Estimates 

* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 

					
					*TOTAL*
* Column 1: Total Deaths

gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
	
	
					
					*INTER*
* Column 2: Inter DTO Killings
gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg), nolog
	


* Table 2. Direct, Indirect, and Total Effects on Violence

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- 		 			log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

	est sto a_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient). Results can be found in Table 2	
esttab a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")

* Table 3. Direct, Indirect, and Total Effects on Violence

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 		log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

	est sto b_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient).
esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways,  se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")


set scheme s1mono
* Figure 1. Predicted Mean of Killings
* US border, pipelines, highways						
gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
				

* Predicted effects 
* Resources distribution
* margins and matrices
qui margins, atmeans at(log_dist_border100=(5.397525  6.346345  6.80697 7.039152)) predict(mu outcome(total_deaths))
matrix margBorder=r(table)
matrix colnames margBorder = 5% 25% 75% 95%

qui margins, atmeans at(log_dist_pipelines=(.2008507 2.370023 4.45474 5.373571)) predict(mu outcome(total_deaths)) 
matrix margPipes=r(table)
matrix colnames margPipes = 5% 25% 75% 95%
matlist margPipes
* .0032736   .0055495   .0092163   .0115254 


qui margins, atmeans at(log_dist_highways=(-3.007695 -1.351678 1.117329 2.480219)) predict(mu outcome(total_deaths)) 
matrix margHighways=r(table)
matrix colnames margHighways = 5% 25% 75% 95%
* .0057262   .0063891   .0075226   .0082323 

* coefplot
coefplot (mat(margBorder), se(2)) (mat(margPipes), se(2)) (mat(margHighways), se(2)), xtitle("")  connect(l) nooffsets vertical legend(label(4 "Distance to Oil Pipelines") label(2 "Distance to US border") label(6 "Distance to Highways") size(small)) ytitle("Predicted Mean of Killings", size(small)) xlabel(1 "5th percentile" 2 "25th percentile" 3 "75 percentile" 4 "95th percentile", labsize(small))




* Figure 2. Predicted Mean of Killings
* Ports, airports
qui margins, atmeans at(log_dist_portsnm=(3.22849 4.372169 5.303523 5.764327)) predict(mu outcome(total_deaths))
matrix margPorts=r(table)
matrix colnames margPorts = 5% 25% 75% 95%
*.0051965   .0064342   .0076085   .0083592 

qui margins, atmeans at(log_dist_airports=(2.663122  3.774534   4.646613  5.136133)) predict(mu outcome(total_deaths))
matrix margAirports=r(table)
matrix colnames margAirports = 5% 25% 75% 95%
*.0051965   .0064342   .0076085   .0083592 


coefplot (mat(margPorts), se(2)) (mat(margAirports), se(2)), xtitle("")  connect(l) nooffsets vertical legend(label(2 "Distance  to Ports") label(4 "Distance to Airports") size(small)) ytitle("Predicted Mean of Killings", size(small)) xlabel(1 "5th percentile" 2 "25th percentile" 3 "75 percentile" 4 "95th percentile", labsize(small))




* Online Appendix

* Appendix 2

* Appendix 2.1 Models without controls

* Table 2.1.1

* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 

* Column 1: Total Deaths 

gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways, nbreg)
			
	

* Column 2: Inter DTO Killings No Interaction

gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways, nbreg)

			

* Table 2.1.2					
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment, nbreg) (fragment <- log_dist_border100 log_dist_pipelines 	log_dist_portsnm log_dist_airports log_dist_highways, nbreg)
			
	nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) 	(Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

	est sto app2te_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab app2te_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")

* Table 2.1.3
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment, nbreg) (fragment <- log_dist_border100 					log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways, nbreg)
			
	nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

	est sto app2ie_`i'
}

	
* Then calculate exponentiated coefficients using exp(coefficient).
esttab app2ie_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")









* Appendix 2.2 Models with additional controls
* Detentions, Opium, PRD Governors, Partisan Change, Employment, and Marginalization Index


* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_detain pan_lajous pri_lajous prd_lajous prigob pangob prdgob illiteracy log_pob grado_marginacion male_occupied opium_percent y1 y2 y3 y4 y5 y6 



* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob prdgob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_marginacion log_pob illiteracy log_pob grado_marginacion male_occupied opium_percent cambio_partido_lajous y1 y2 y3 y4 y5 y6 


* Table 2.2.1
* Column 1: Total Deaths No Interaction

gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
			
	

* Column 2: Inter DTO Killings No Interaction

gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)


							
* Table 2.2.2
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- 			 	log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

	est sto app3te_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient).
esttab app3te_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")

* Table 2.2.3				
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- 	 			log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

	est sto app3ie_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab app3ie_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")






* Appendix 2.3 Multilevel Models

* Table 2.3.2 
* Control Variables First Step: Number of Groups
global x1 prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 
						

						*TOTAL*
* Column 1: Total Deaths No Interaction

gsem(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment $x2  M1[id_estado], nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1 M2[id_estado], nbreg), cov(M1[id_estado]*M2[id_estado]@0)
			

					
					*INTER*
* Column 2: Inter DTO Killings No Interaction

gsem(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment y1 y2 y3 y4 y5 y6  prigob pangob  grado_rezago log_pob illiteracy  M1[id_estado], nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways y1 y2 y3 y4 y5 y6  prigob pangob grado_rezago log_pob illiteracy M2[id_estado], nbreg), cov(M1[id_estado]*M2[id_estado]@0)

	
							
* Table 2.3.3			
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{
				
	qui: gsem  (total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment $x2 M1[id_estado], nbreg) (fragment <- log_dist_border100 		log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1 M2[id_estado], nbreg), cov(M1[id_estado]*M2[id_estado]@0)
			
	nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

	est sto ml1_`i'
}

	
* Then calculate exponentiated coefficients using exp(coefficient).
esttab ml1_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")

* Table 2.3.4. 
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

qui: gsem  (inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment $x2 M1[id_estado], nbreg) (fragment <- log_dist_border100 	log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1 M2[id_estado], nbreg), cov(M1[id_estado]*M2[id_estado]@0)

			
	nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

	est sto ml2_`i'
}
	
* Then calculate exponentiated coefficients using exp(coefficient).
esttab ml2_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")	


* Appendix 2.4. Models with State Fixed Effects

* Table 2.4.1 
* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 i.id_estado 			


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 i.id_estado 


* Column 1: Total Deaths No Interaction

gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- 			 		log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
			
	

* Column 2: Inter DTO Killings No Interaction

gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- 				log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)


* Table 2.4.2					
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- 				log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

	est sto app4te_`i'
}

	
* Then calculate exponentiated coefficients using exp(coefficient).
esttab app4te_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")

* Table 2.4.3
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm 	log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- 		 		log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

	est sto app4ie_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab app4ie_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")


* Appendix 2.5 Models without ten most violent localities
* IMPORTANT NOTE: Run all models in this section. From line 420 to line 500
* Table 2.5.1
preserve
* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


*Keep only observations of the sample
qui: gsem (total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
				
keep if e(sample)==1


*Dummy of outliers
	bysort cvegeo_str: egen mean_total_deaths=mean(total_deaths)

	sort mean_total_deaths

	egen new_id=group(cvegeo_str)

	sort mean_total_deaths new_id year

	gen rank=_n

	gen outlier=0
	replace outlier=1 if rank>235947

	keep if outlier!=1

* Column 1: Total Deaths No Interaction

	gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
			


* Column 2: Inter DTO Killings No Interaction

	gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)


	
* Table 2.5.2							
					
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 	log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

	est sto app8te_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab app8te_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")


* Table 2.5.3

*INTER DTO DEATHS*

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

		
foreach i of varlist `resources'{

	qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
			
	nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

	est sto app8ie_`i'
}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab app8ie_*, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")

restore



* Appendix 2.6 Models with Robust Standard Errors

* Table 2.6.1
* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 

					*NO INTERACTION*
						
						*TOTAL*
* Column 1: Total Deaths No Interaction

gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg), vce(cluster cvegeo)
					
						
*INTER*
* Column 2: Inter DTO Killings No Interaction

gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg), vce(cluster cvegeo)
		


* Table 2.6.2
* Effects * 
*TOTAL DEATHS*

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
	foreach i of varlist `resources'{

		qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- 		 		log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg), vce(cluster cvegeo)
				
		nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto a_`i'
	}


* Then calculate exponentiated coefficients using exp(coefficient).	
esttab a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")


* Table 2.6.3

*INTER DTO DEATHS*

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
	foreach i of varlist `resources'{

		qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- 		  	log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg), vce(cluster cvegeo)
				
		nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto b_`i'
	}

		
* Then calculate exponentiated coefficients using exp(coefficient).	
esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compres b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")




* Appendix 2.7 Models with Different Border Measures

* Table 2.7.1
* Table 2.7.2


global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 
						
						
local borders  log_dist_border100   log_dist_border50 log_dist_border log_dist_ports_entry log_dist_ports_highways


	foreach i of varlist `borders'{
	
	qui: gsem	(total_deaths <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
				
		est sto bo1_`i'
		
	qui: gsem	(inter_dto_kill <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
				
		est sto bo2_`i'
	}

				
* Then calculate exponentiated coefficients using exp(coefficient).	
* Only the first two panels of each output were reported, the rest is the same.
esttab bo1_*, eform se label starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels b(%10.3f) scalars("Localities" "ll Log likelihood" "Time Fixed Effects" "Controls") drop($x1 $x2 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways) interaction("x") mtitles("Total Deaths" "Total Deaths" "Total Deaths" "Total Deaths" "Total Deaths" "Inter DTO Deaths" "Inter DTO Deaths" "Inter DTO Deaths" "Inter DTO Deaths" "Inter DTO Deaths")

esttab bo2_*, eform se label starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels b(%10.3f) scalars("Localities" "ll Log likelihood" "Time Fixed Effects" "Controls") drop($x1 $x2 log_dist_pipelines log_dist_portsnm	log_dist_airports log_dist_highways) interaction("x") mtitles("Inter DTO Deaths" "Inter DTO Deaths" "Inter DTO Deaths" "Inter DTO Deaths" "Inter DTO Deaths")



* Table 2.7.3
* Table 2.7.4

local borders  log_dist_border100   log_dist_border50 log_dist_border log_dist_ports_entry log_dist_ports_highways

	foreach i of varlist `borders' {
		qui: gsem	(total_deaths <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
		
		nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto eb1_`i'	
		
		
		
		qui: gsem	(inter_dto_kill <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- `i' log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
		
		nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto eb2_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).	
* Only the first two panels of each output were reported, the rest is the same.
esttab eb1_*, eform se label b(%10.3f) starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels mtitles("Border 100" "Border 50" "Border" "Ports Entry" "Ports Entry Closest to Highways")

esttab eb2_*, eform se label b(%10.3f)  starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress nobaselevels mtitles("Border 100" "Border 50" "Border" "Ports Entry" "Ports Entry Closest to Highways")

* Appendix 2.8 Models with Cross Section Design
* IMPORTANT NOTE: Run all models in this section. From line 639 to line 747
* Table 2.8.1
preserve
* X
global distances log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways

* Control Variables First Step: Number of Groups
global x1  pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob  illiteracy male_occupied opium_percent 


* Control Variables Second Step: Violence
global x2 zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana cambio_partido_lajous 


* Collapse
collapse (sum) total_deaths inter_dto_kill fragment dto_kill (mean) $distances $x1 $x2, by(cvegeo)

* Change repression variable
gen log_dto_kill=ln(dto_kill+1)

* Control Variables First Step: Number of Groups
global x1  log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy male_occupied opium_percent 

* Control Variables Second Step: Violence
global x2 zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy cambio_partido_lajous 


	* Rename variables
	la var inter_dto_kill "Inter DTO Deaths"
	la var log_dist_border100 "Distance to Closest Border Segment"
	la var log_dist_pipelines "Distance to Closest Pipeline (logged)"
	la var log_dist_portsnm "Distance to Closest Port (logged)"
	la var log_dist_airports "Distance to Closest Airport (logged)"
	la var log_dist_highways "Distance to Closest Highway (logged)"
	la var fragment "Number of DTOs"
	la var pan_lajous "PAN mayor"
	la var pri_lajous "PRI mayor"
	la var prd_lajous "PRD mayor"
	la var prigob "PRI governor"
	la var pangob "PAN governor"
	la var zetas "Zetas"
	la var beltran_leyva2 "Beltran Leyva"
	la var sinaloa2 "Sinaloa"
	la var familia "Familia"
	la var golfo "Golfo"
	la var juarez "Juarez"
	la var tijuana "Tijuana"
	la var grado_rezago "Social Backwardness"
	la var log_pob "Population (logged)"
	la var illiteracy "Schooling"
	la var male_occupied "Percent of Occupied Male"
	la var opium_percent "Opium Suitability Area"
	la var cambio_partido_lajous "Party Change"
	la var log_dto_kill "Killed DTO Members (logged)"
	la var total_deaths "Total Deaths"


*NO INTERACTION*
						
*TOTAL*
* Column 1: Total Deaths No Interaction

gsem	(total_deaths <- $distances fragment $x2, nbreg) (fragment <- $distances  $x1, nbreg), vce(cluster cvegeo)
		

						
						
*INTER*
* Column 2: Inter DTO Killings No Interaction

gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines   log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg), vce(cluster cvegeo)
		
	

* Table 2.8.2
								
*TOTAL DEATHS*

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
foreach i of varlist `resources'{

qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg), vce(cluster cvegeo)
				
nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto a_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).			
esttab a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")

* Table 2.8.3
								*INTER DTO DEATHS*

	local resources log_dist_pipelines log_dist_border100 log_dist_portsnm 	log_dist_airports 	log_dist_highways

			
foreach i of varlist `resources'{

	qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg), vce(cluster cvegeo)
				
	nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto b_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).			
esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")	
restore




* Appendix 2.9 Models with Additional Interactions
* Section 2.9A Refineries and Distance to Oil Pipelines

* Table 2.9.A.1
* Refineries * 
* salamanca 11027
* minatitlan 30108
* madero 28009
* cadereyta 19009
* salina cruz 20079
* tula 13076
gen refinery_dummy=.
replace refinery_dummy=1 if id_municipio==11027|id_municipio==30108|id_municipio==28009|id_municipio==19009|id_municipio==20079|id_municipio==13076
replace refinery_dummy=0 if refinery_dummy==.


la var refinery_dummy "Refinery"
tab refinery_dummy

gen refinery_pipelines=refinery_dummy*log_dist_pipelines
sum refinery_pipelines
la var refinery_pipelines "Refinery x Distance to Closest Pipeline (logged)"

* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 

* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 

						
						*TOTAL*
* Column 1: Total Deaths

gsem	(total_deaths <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
		
						
						*INTER*
* Column 2: Inter DTO Killings

gsem 	(inter_dto_kill <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg), nolog
		
		


* Table 2.9.A.2
								
*TOTAL DEATHS*
local resources log_dist_pipelines refinery_dummy refinery_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
foreach i of varlist `resources'{

	qui: gsem	(total_deaths <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2,      nbreg) (fragment <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
				
	nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto a_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways a_refinery_dummy a_refinery_pipelines, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border"  "Distance to Closest Port" "Distance to Closest Airport"  "Distance to Closest Highway" "Refinery" "Refinery x Distance to Closest Pipeline")

* Table 2.9.A.3

local resources log_dist_pipelines refinery_dummy refinery_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
foreach i of varlist `resources'{

qui: gsem	(inter_dto_kill <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 refinery_dummy log_dist_pipelines refinery_pipelines log_dist_portsnm log_dist_airports log_dist_highways $x1, nbreg)
				
 nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto b_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways b_refinery_dummy b_refinery_pipelines, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border"  "Distance to Closest Port" "Distance to Closest Airport"  "Distance to Closest Highway" "Refinery" "Refinery x Distance to Closest Pipeline")

* Section 2.9B Law Enforcement and Distance to Highways
gen repress_dummy=.
replace repress_dummy=1 if lagged_log_dto_kill>.2077572 & lagged_log_dto_kill!=. 
replace repress_dummy=0 if lagged_log_dto_kill<= .2077572 & lagged_log_dto_kill!=.
tab repress_dummy, mis
la var repress_dummy "Killed DTOs"


gen repress_highways=repress_dummy*log_dist_highways			
la var repress_highways "Killed DTOs x Distance to Closest Highway"	

* Table 2.9.B.1
* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 	familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6


	
*TOTAL*
* Column 1: Total Deaths
gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports  log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports i.repress_dummy log_dist_highways repress_highways  $x1, nbreg)
	
*INTER*
* Column 2: Inter DTO Killings
gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines 				log_dist_portsnm log_dist_airports  log_dist_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports i.repress_dummy log_dist_highways repress_highways $x1, nbreg), nolog
		



* Table 2.9.B.2

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm 	log_dist_airports log_dist_highways repress_highways repress_dummy

			
	foreach i of varlist `resources'{

		qui: gsem	(total_deaths <- log_dist_border100 ///
					log_dist_pipelines ///
					log_dist_portsnm log_dist_airports log_dist_highways  ///
					fragment lagged_total_deaths $x2, nbreg) ///
				(fragment <- log_dist_border100 ///
					log_dist_pipelines ///
					log_dist_portsnm log_dist_airports ///
					repress_dummy log_dist_highways repress_highways  $x1, nbreg)
					
		if `i'!= repress_highways {
			
			nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) ///
				(Direct:_b[total_deaths:`i']) ///
				(Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto a_`i'
		} 
		
		else {
			
			nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]), post

		est sto a_`i'

		}
	}


esttab a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways a_repress_dummy a_repress_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway" "Killed DTOs" "Killed DTOs x Distance to Closest Highway")


* Table 2.9.B.3
*INTER DTO DEATHS*
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports 	log_dist_highways repress_highways repress_dummy

	foreach i of varlist `resources'{

		qui: gsem	(inter_dto_kill <- log_dist_border100 ///
					log_dist_pipelines ///
					log_dist_portsnm log_dist_airports log_dist_highways  ///
					fragment lagged_total_deaths $x2, nbreg) ///
				(fragment <- log_dist_border100 ///
					log_dist_pipelines ///
					log_dist_portsnm log_dist_airports ///
					repress_dummy log_dist_highways repress_highways  $x1, nbreg)
					
		if `i'!= repress_highways {
			
			nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) ///
					(Direct:_b[inter_dto_kill:`i']) ///
					(Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto b_`i'
		} 
		
		else {
			
			nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]), post

		est sto b_`i'

		}
	}

esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways b_repress_dummy b_repress_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway" "Killed DTOs" "Killed DTOs x Distance to  Closest Highway")

* In all equations

* Table 2.9.B.4
* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 	familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6

						
						*TOTAL*
	* Column 1: Total Deaths

gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports  repress_dummy log_dist_highways repress_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports repress_dummy log_dist_highways repress_highways  $x1, nbreg)
		
						
						*INTER*
	* Column 2: Inter DTO Killings

gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports  repress_dummy log_dist_highways repress_highways fragment lagged_inter_kill $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports repress_dummy log_dist_highways repress_highways $x1, nbreg), nolog
		


* Table 2.9.B.5
								
*TOTAL DEATHS*

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways repress_dummy repress_highways

			
	foreach i of varlist `resources'{

		qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports repress_dummy log_dist_highways repress_highways fragment lagged_total_deaths 		$x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports repress_dummy log_dist_highways repress_highways  $x1, nbreg)
					
		
			
			nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto a_`i'
		
	}

* Then calculate exponentiated coefficients using exp(coefficient).
esttab a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways a_repress_dummy a_repress_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway" "Killed DTOs" "Killed DTOs x Distance to Closest Highway")


* Table 2.9.B.6
								*INTER DTO DEATHS*
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways repress_dummy repress_highways

	foreach i of varlist `resources'{

		qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports repress_dummy log_dist_highways repress_highways fragment lagged_total_deaths 			$x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports repress_dummy log_dist_highways repress_highways  $x1, nbreg)
					
		
			
			nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto b_`i'
	}


* Then calculate exponentiated coefficients using exp(coefficient).						
esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways b_repress_dummy b_repress_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway" "Killed DTOs" "Killed DTOs x Distance to Closest Highway")
								
* Appendix 2.10 Models with Urban Indicators

* Section 2.10.A. INEGI criterion

* Table 2.10.A.1
					* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* TOTAL *
* Urban *
gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths urban2 $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  urban2 $x1, nbreg)

* INTER *
* Urban *
gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill urban2 $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways urban2 $x1, nbreg)
	


* Table 2.10.A.2
*TOTAL DEATHS*
*Urban*

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
	foreach i of varlist `resources'{

		qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths urban2 $x2, nbreg) (fragment <- 		log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways urban2 $x1, nbreg) 
				
		nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto a_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).	

esttab  a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")
	
* Table 2.10.A.3
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
	foreach i of varlist `resources'{

		qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill urban2 $x2, nbreg) (fragment <- 			log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways urban2 $x1, nbreg)
				
		nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto b_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport"	"Distance to Closest Highway")


* Section 2.10B. INEGI threshold

* Table Table 2.10.B.1. 
gen urban3=.
replace urban3=1 if pob1!=. & pob1>=2500
replace urban3=0 if pob1!=. & pob1<2500

* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 

* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* TOTAL *
* Urban *
gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths urban3 $x2, nbreg)	(fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways urban3 $x1, nbreg)
	

* INTER *
* Urban *
gsem 	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill urban3 $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways urban3 $x1, nbreg)
	

* Table 2.10.B.2. 
								
local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways
		
	foreach i of varlist `resources'{

		qui: gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths urban3 $x2, nbreg) (fragment <- 			log_dist_border100	log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways urban2 urban3 $x1, nbreg) 
				
		nlcom	(Indirect:_b[total_deaths:fragment]*_b[fragment: `i' ]) (Direct:_b[total_deaths:`i']) (Total:_b[total_deaths:`i']+_b[total_deaths:fragment]*_b[fragment:`i']), post

		est sto a_`i'
	}

* Then calculate exponentiated coefficients using exp(coefficient).	
esttab a_log_dist_pipelines a_log_dist_border100 a_log_dist_portsnm a_log_dist_airports a_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")
	
* Table 2.10B.3. 

local resources log_dist_pipelines log_dist_border100 log_dist_portsnm log_dist_airports log_dist_highways

			
	foreach i of varlist `resources'{

		qui: gsem	(inter_dto_kill <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_inter_kill urban3 $x2, nbreg) (fragment <- 			log_dist_border100  log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways urban3 $x1, nbreg)
				
		nlcom	(Indirect:_b[inter_dto_kill:fragment]*_b[fragment: `i' ]) (Direct:_b[inter_dto_kill:`i']) (Total:_b[inter_dto_kill:`i']+_b[inter_dto_kill:fragment]*_b[fragment:`i']), post

		est sto b_`i'
	}


* Then calculate exponentiated coefficients using exp(coefficient).	
esttab b_log_dist_pipelines b_log_dist_border100 b_log_dist_portsnm b_log_dist_airports b_log_dist_highways, se eform label noomitted starlevels(# 0.10 * 0.05 ** 0.01 *** 0.001) nogaps compress b(%10.3f) mtitles("Distance to Closest Pipeline" "Distance to US Border" "Distance to Closest Port" "Distance to Closest Airport" "Distance to Closest Highway")


* Appendix 3. Additional Predicted Effects
* Marginal Effects by Resource Group and Population*			
* Predicted effects 
* Resources distribution + Population distribution

* Control Variables First Step: Number of Groups
global x1 lagged_fragment lagged_log_dto_kill pan_lajous pri_lajous prd_lajous prigob pangob grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


* Control Variables Second Step: Violence
global x2 pan_lajous pri_lajous prd_lajous prigob pangob zetas beltran_leyva2 sinaloa2 familia golfo juarez tijuana grado_rezago log_pob illiteracy y1 y2 y3 y4 y5 y6 


gsem	(total_deaths <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways fragment lagged_total_deaths $x2, nbreg) (fragment <- log_dist_border100 log_dist_pipelines log_dist_portsnm log_dist_airports log_dist_highways  $x1, nbreg)
					
* Figure 3.1 and 3.2
** Border, pipes, highways
margins, atmeans at(log_dist_border100=(5.397525  6.346345  6.80697 7.039152) log_pob=(5.170484)) predict(mu outcome(total_deaths))
matrix margBorder=r(table)
matrix colnames margBorder = 5% 25% 75% 95%

margins, atmeans at(log_dist_pipelines=(.2008507 2.370023 4.45474 5.373571) log_pob=(5.170484)) predict(mu outcome(total_deaths)) 
matrix margPipes=r(table)
matrix colnames margPipes = 5% 25% 75% 95%


margins, atmeans at(log_dist_highways=(-3.007695 -1.351678 1.117329 2.480219) log_pob=(5.170484)) predict(mu outcome(total_deaths)) 
matrix margHighways=r(table)
matrix colnames margHighways = 5% 25% 75% 95%

set scheme s1mono
* coefplot 
coefplot (mat(margBorder), se(2)) (mat(margPipes), se(2)) (mat(margHighways), se(2)), xtitle("")  connect(l) nooffsets vertical legend(label(4 "Distance to Oil Pipelines") label(2 "Distance to US border") label(6 "Distance to Highways") size(small)) ytitle("Predicted Mean of Killings", size(small)) xlabel(1 "5th percentile" 2 "25th percentile" 3 "75 percentile" 4 "95th percentile", labsize(small))


graph export c1pop5.png, as(png) replace


margins, atmeans at(log_dist_border100=(5.397525  6.346345  6.80697 7.039152) log_pob=(8.239594)) predict(mu outcome(total_deaths))
matrix margBorder=r(table)
matrix colnames margBorder = 5% 25% 75% 95%

margins, atmeans at(log_dist_pipelines=(.2008507 2.370023 4.45474 5.373571) log_pob=(8.239594)) predict(mu outcome(total_deaths)) 
matrix margPipes=r(table)
matrix colnames margPipes = 5% 25% 75% 95%


margins, atmeans at(log_dist_highways=(-3.007695 -1.351678 1.117329 2.480219) log_pob=(8.239594)) predict(mu outcome(total_deaths)) 
matrix margHighways=r(table)
matrix colnames margHighways = 5% 25% 75% 95%

* coefplot 
coefplot (mat(margBorder), se(2)) (mat(margPipes), se(2)) (mat(margHighways), se(2)), xtitle("")  connect(l) nooffsets vertical legend(label(4 "Distance to Oil Pipelines") label(2 "Distance to US border") label(6 "Distance to Highways") size(small)) ytitle("Predicted Mean of Killings", size(small)) xlabel(1 "5th percentile" 2 "25th percentile" 3 "75 percentile" 4 "95th percentile", labsize(small))


graph export c1pop95.png, as(png) replace

** Ports, Airports
margins, atmeans at(log_dist_portsnm=(3.22849 4.372169 5.303523 5.764327) log_pob=(5.170484)) predict(mu outcome(total_deaths))
matrix margPorts=r(table)
matrix colnames margPorts = 5% 25% 75% 95%

margins, atmeans at(log_dist_airports=(2.663122  3.774534   4.646613  5.136133) log_pob=(5.170484)) predict(mu outcome(total_deaths))
matrix margAirports=r(table)
matrix colnames margAirports = 5% 25% 75% 95%


coefplot (mat(margPorts), se(2)) (mat(margAirports), se(2)), xtitle("")  connect(l) nooffsets vertical legend(label(2 "Distance  to Ports") label(4 "Distance to Airports") size(small)) ytitle("Predicted Mean of Killings", size(small)) xlabel(1 "5th percentile" 2 "25th percentile" 3 "75 percentile" 4 "95th percentile", labsize(small))

graph export c2pop5.png, as(png) replace



margins, atmeans at(log_dist_portsnm=(3.22849 4.372169 5.303523 5.764327) log_pob=(8.239594)) predict(mu outcome(total_deaths))
matrix margPorts=r(table)
matrix colnames margPorts = 5% 25% 75% 95%

margins, atmeans at(log_dist_airports=(2.663122  3.774534   4.646613  5.136133) log_pob=(8.239594)) predict(mu outcome(total_deaths))
matrix margAirports=r(table)
matrix colnames margAirports = 5% 25% 75% 95%


coefplot (mat(margPorts), se(2)) (mat(margAirports), se(2)), xtitle("")  connect(l) nooffsets vertical legend(label(2 "Distance  to Ports") label(4 "Distance to Airports") size(small)) ytitle("Predicted Mean of Killings", size(small)) xlabel(1 "5th percentile" 2 "25th percentile" 3 "75 percentile" 4 "95th percentile", labsize(small))

graph export c2pop95.png, as(png) replace
